/*
 * Copyright (c) 2020.版权所有高金磊
 */

package 领扣算法.AA中等题.不同路径II;

public class Main {

    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        obstacleGrid[0][0]=obstacleGrid[0][0]==0?1:0;
        for (int i = 1; i < obstacleGrid.length; i++) {

               obstacleGrid[i][0]=obstacleGrid[i][0]==1?0:obstacleGrid[i-1][0];
        }
        for (int i = 1; i < obstacleGrid[0].length; i++) {
            obstacleGrid[0][i]=obstacleGrid[0][i]==1?0:obstacleGrid[0][i-1];
        }

        for (int i = 1; i < obstacleGrid.length; i++) {
            for (int j = 1; j < obstacleGrid[0].length; j++) {
                if (obstacleGrid[i][j]==1)
                {
                    obstacleGrid[i][j]=0;
                }
                else obstacleGrid[i][j]=obstacleGrid[i-1][j]+obstacleGrid[i][j-1];
            }

        }
        return obstacleGrid[obstacleGrid.length-1][obstacleGrid[0].length-1];
    }
}
